package com.zrrd.jsonDemo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zrrd.javaWeb.bean.User;

/**
 * @author WanJl
 * @version 1.0
 * @title jsonDemo01
 * @description
 * @create 2024/1/20 16:07
 */
public class jsonDemo01 {
    public static void main(String[] args) {
        // 1、java对象转换成JSON字符串
        User user=new User(1,"zhangsan","123456","张三",25,"男","13636363366");

        String jsonStr = JSON.toJSONString(user);
        System.out.println(jsonStr);
        //{"age":25,"gender":"男","password":"123456","phone":"13636363366","realname":"张三","uid":1,"username":"zhangsan"}




        // 2、JSON字符串转换成Java对象
        User user1 = JSON.parseObject(jsonStr, User.class);
        System.out.println(user.toString());

    }
}
